"""
    Serves as proxy to Delicious API
 
    @author Jean-Lou Dupont

    - Respects the 1second rate limit
    - Caches the responses from Delicious
    - Provides a JSONP reply format back to client

    Rate Limiting:
    ==============
    - Verify that user U is valid (i.e. verify API key) 
    
    - For user U, verify if request has a response in memcache
      - IF yes, then return it
      - IF no, then proceed
      
    - For user U, verify if 'timeout flag' exists in memcache
      - IF yes, then send back Throttle Signal (?)
      - IF no, then proceed
      
    - For user U, send request to Delicious
      - IF response received, send using JSONP protocol
        

"""
import os
import sys
import logging

import wsgiref.handlers
from google.appengine.ext           import webapp

from libs.user.prefs import UserPrefs

class ServiceDelicious( webapp.RequestHandler ):
    """
    Delicious
    """

    def __init__(self):
        pass

    def get(self, api_key, callback, rq ):
        logging.info( "ServiceDelicious: api_key[%s] callback[%s] rq[%s]" % (api_key, callback, rq))
        
        
        # template replacement & rendering
        self.response.out.write(template.render(path, template_values))
        

#========================================================================================================
def main():
  application = webapp.WSGIApplication([('/srv/delicious/(.*?)/(.*?)/(.*)', ServiceDelicious)], debug=True)
  wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
    main()